package com.ruoyi.web.controller.market.product;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.db.model.param.ProductInfoParam;
import com.ruoyi.extend.enums.ChannelTypeEnum;
import com.ruoyi.product.enums.ProdPriceEnum;
import com.ruoyi.product.enums.ProdTypeEnum;
import com.ruoyi.web.service.IProductService;
import com.ruoyi.web.wapper.ProductInfoWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ProductInfo;
import com.ruoyi.product.service.IProductInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品信息（下游/甲方）Controller
 * 
 * @author ruoyi
 * @date 2022-07-31
 */
@Controller
@RequestMapping("/product/info")
public class ProductInfoController extends BaseController
{
    private String prefix = "product/info";

    @Autowired
    private IProductInfoService productInfoService;
    @Autowired
    IProductService productService;

    @RequiresPermissions("product:info:view")
    @GetMapping()
    public String info(ModelMap mmap)
    {

        // 产品信息
        List<Map<String, Object>> productMapList = productInfoService.listMap(new ProductInfo());
        mmap.put("productList", productMapList);

        List<Map<String, Object>> channelTypeList = ProdPriceEnum.getListMap();
        mmap.put("proPriceList", channelTypeList);

        return prefix + "/info";
    }

    /**
     * 查询产品信息（下游/甲方）列表
     */
    @RequiresPermissions("product:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductInfo productInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = productInfoService.selectProductInfoListMap(productInfo);
        mapList = new ProductInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出产品信息（下游/甲方）列表
     */
    @RequiresPermissions("product:info:export")
    @Log(title = "产品信息（下游/甲方）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductInfo productInfo)
    {
        List<ProductInfo> list = productInfoService.selectProductInfoList(productInfo);
        ExcelUtil<ProductInfo> util = new ExcelUtil<ProductInfo>(ProductInfo.class);
        return util.exportExcel(list, "产品信息（下游/甲方）数据");
    }

    /**
     * 新增产品信息（下游/甲方）
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {

        List<Map<String, Object>> channelTypeList = ProdPriceEnum.getListMap();
        mmap.put("proPriceList", channelTypeList);

        List<Map<String, Object>> prodTypeList = ProdTypeEnum.getListMap();
        mmap.put("prodTypeList", prodTypeList);

        return prefix + "/add";
    }

    /**
     * 新增保存产品信息（下游/甲方）
     */
    @RequiresPermissions("product:info:add")
    @Log(title = "产品信息（下游/甲方）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductInfo productInfo)
    {
        return productService.addProductInfo(productInfo);
    }

    /**
     * 修改产品信息（下游/甲方）
     */
    @RequiresPermissions("product:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductInfo productInfo = productInfoService.selectProductInfoById(id);
        mmap.put("productInfo", productInfo);

        List<Map<String, Object>> channelTypeList = ProdPriceEnum.getListMap();
        mmap.put("proPriceList", channelTypeList);

        List<Map<String, Object>> prodTypeList = ProdTypeEnum.getListMap();
        mmap.put("prodTypeList", prodTypeList);

        return prefix + "/edit";
    }

    /**
     * 修改保存产品信息（下游/甲方）
     */
    @RequiresPermissions("product:info:edit")
    @Log(title = "产品信息（下游/甲方）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductInfo productInfo)
    {
        return toAjax(productInfoService.updateProductInfo(productInfo));
    }

    /**
     * 删除产品信息（下游/甲方）
     */
    @RequiresPermissions("product:info:remove")
    @Log(title = "产品信息（下游/甲方）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productInfoService.deleteProductInfoByIds(ids));
    }
}
